<?php 

$CI =& get_instance();
$CI->load->database();
$CI->load->library("front/header_lib");
$query_pages = $CI->db->get_where('bur_staticpages',array('staticpage_link'=>'design_directory'));
foreach($query_pages->result() as $row_vals)
{
    $title = $row_vals->staticpage_title;
	$metakey_page = $row_vals->staticpage_metakey;
    $metadesc_page = $row_vals->staticpage_metadesc;  
}
$CI->header_lib->display_header_element(array("script"=>array("jquery-1.4.2","jquery.validate.pack","jquery.NobleCount.min","ajaxfileupload","si.files"),"page_title"=>$title,"metakey_page"=>$metakey_page,"metadesc_page"=>$metadesc_page));

$datas[''] = '';

$CI->header_lib->display_header($datas);

$data['company_info'] = 1 ;
$CI->load->model('Directory_company_model');
//echo $CI->session_user_id;
$count = $CI->Directory_company_model->get_view_count($CI->session_user_id);
$listing_active = $CI->Directory_company_model->get_listing_status($CI->session_user_id);

$data['view_count'] = $count['view_count'];
$data['lead_count'] = $count['lead_count'];
$left_class['company_info'] = 1;
?>
<script type="text/javascript" src="<? echo site_url();?>/js/jquery.maskedinput-1.0.js"></script>

<style type="text/css" title="text/css">
.SI-FILES-STYLIZED label.cabinet
{
    width: 100px;
    height: 28px;
    background: url(<?php echo base_url()?>image/select_image.jpg) 0 0 no-repeat;
    display: block;
    overflow: hidden;
    cursor: pointer;
}

.SI-FILES-STYLIZED label.cabinet input.file
{
    position: relative;
    height: 100%;
    width: auto;
    opacity: 0;
    -moz-opacity: 0;
    filter:progid:DXImageTransform.Microsoft.Alpha(opacity=0);
	z-index:2; 
}



/* Style for jquery validation */
#company_form label.error {    
    background-color: #cccc00;    
    color: #000;    
    padding: 5px 10px;    
    width: 320px;    
    margin: 0 0 0 0px;    
    float: none;    
    height:19px;    
    line-height:19px;
    position:relative;
    display:block;
    font-weight: normal;
}
</style>
<script type="text/javascript">
SI.Files.stylizeAll();
  $(document).ready(function(){
      var result = true;   
      $("#contact_number").mask("(999) 999-9999"); 
     /* $.validator.addMethod("comapanyCheck", function() {                                                
            $.post("<?php echo site_url('json_request/check_company_json')?>" ,{
                 company: $('#name').val()                                 
            },function(data){
                result = (data=="TRUE") ? true : false;
            }, "json");
                return result;            
      });
    
      $("#company_form").validate({                
        onkeyup: false,                
        rules: {            
            name: {
                required : true,
                comapanyCheck : true    
            },
            description : "required",
            contact_number : "required",
            contact_email : "email",
            province_id : "required",
            city_name : "required",
            physical_street : "required",
            physical_suburb : "required",
            physical_city : "required"                        
                    
        },        
        messages: {            
            name: {
                required : "Please input a Name",
                comapanyCheck : "Duplicate  name exists in directory"    
            },            
            description : "Please input a  Description",
            contact_number : "Please input a Telephone Number for customers",
            contact_email : "Please input the valid email address",
            province_id : "Please select a Province/Region",
            city_name : "Please input a City or Town",
            physical_street : "Please input a Street Address",
            physical_suburb : "Please input a Suburb",
            physical_city : "Please input a City or Town"
        }          
      });*/
      
        $('#text_detail').NobleCount('#count_detail',{
        	max_chars: 5000,
        	block_negative: true
        });

 });  
// function upload jquery
function ajaxFileUpload(){
    $("#loading")
    .ajaxStart(function(){
        $(this).show();
    })
    .ajaxComplete(function(){
        $(this).hide();
    });

    $.ajaxFileUpload({
        url:'<?php echo site_url('ajax_upload/upload_directory_image/upload/company/network')?>/<?php echo $company_detail['company_slug_name']?>',
        secureuri:false,
        fileElementId:'fileToUpload',
        dataType: 'json',
        success: function (data, status){
            if(typeof(data.error) != 'undefined')
            {
                if(data.error != ''){
                    $("#info").html('<span width="150" height="150">'+data.error+"</span>");
                }else{                        
                    $("#info").html('<img src="<?php echo base_url();?>uploads/directory/company_logo/thumb/'+data.msg
                    +'" width="150" />'
                    +'<input type="hidden" name="upload" value="'+data.msg +'">');
                }
            }
        },
        error: function (data, status, e){
            $("#info").html(e);
        }
    })        
    return false;
}

function clear_logo(){
    $("#info").html('<img src="<?php echo base_url()?>xhtml/img/forlogo2.gif" width="160" height="160">'
    + '<input type="hidden" name="upload" value="">');
    return false;    
}
</script>
<!--body content starts-->
<div id="container_wrapper">
	<div id="body_container">
    	<div class="left_part">
        
            <?php echo $CI->header_lib->display_panel_left($data);?>
        </div>
    	
        <div class="right_part">
       		<div class="wright">
                	<h2 style="display:none">
                <?php 
                if(!empty($company_detail['company'])){
                	echo $company_detail['company'];
                }else{
                	echo "Company name not defined yet";
                } 
                ?></h2>
                
                <?php if ($messageBox != ''):?>
                <br/>
                <div style="background-color:#CF118C; color:#FFF; font-size:14px; margin-bottom:5px; padding:5px;"><?php echo $messageBox;?></div>
                <?php endif;?>
       		 <?php
                $attributes = array('id' => 'company_form'); 
                echo form_open_multipart('directory/panel/company',$attributes);?>
                
            <div class="email_section001">
            	<ul>
                	<li>
                    	<div class="list_div031"><h3 class="style18">Your details</h3></div>
                    	<div class="list_div04"><p style="padding-top:5px;" class="txt12">Name: <span>(Optional)</span></p></div>
                        <div class="clear"></div>
                   	</li>
                    <li>
                    	<div class="list_div031">
                        <div class="height10"></div>
                        <p class="redTxt12">Input your details here to DISPLAY on your advert in the directory.</p>
                    	</div>
                    	<div class="list_div04">
                        <?php 
                        $input_company = array('name' => 'name','id' => 'name', 'class' => 'large_input', 'value' => set_value('name',$company_detail['company'])); 
                        echo form_input($input_company);//form_input('name',$company_detail['company']); ?>
                        <?php echo form_error('name','<p id="error_recaptcha" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?>
                        </div>
                        <div class="clear"></div>
                   	</li>
                    <li>
                    	<div class="list_div031">
                        <div class="height10"></div>
                        <div class="height50"></div>
                        <p style="font-size:14px;">You have <strong id="count_detail" class="redTxt12">5000</strong> characters left</p></div>
                    	<div class="list_div04">
                        <p class="txt12">Description: <span>(Optional)</span></p>
                        <div class="height10"></div>
                        <?php echo form_textarea(array('name'=>'description', 'class' => 'textarea_style','id'=>'text_detail'),set_value('description',$company_detail['company_description'])); ?>
                <?php echo form_error('description','<p id="error_recaptcha" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?>
                        <div class="height10"></div>
                        <ul>
                            	<li>
                            	  <p class="txt12">Telephone Number: <span>(optional)</span></p></li>
                                <li>
                                <?php echo form_input(array('name'=>'contact_number','id' => 'contact_number'),set_value('contact_number',$company_detail['company_contact_number'])); ?>
                <?php echo form_error('contact_number','<p id="error_recaptcha" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?></li>
                                <li>
                                  <p class="txt12">Fax Number: <span>(optional)</span></p></li>
                                <li> 
                                <?php echo form_input('fax_number',set_value('fax_number',$company_detail['fax_number'])); ?>
                <?php echo form_error('fax_number','<p id="error_recaptcha" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?></li>
                                <li>
                                  <p class="txt12">Email: <span>(optional)</span></p></li>
                                <li>
                                 <?php echo form_input('contact_email',set_value('company_contact_email',$company_detail['company_contact_email'])); ?>
                <?php echo form_error('contact_email','<p id="error_recaptcha" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?>
                                </li>
                                <li>
                                  <p class="txt12">Website: <span>(optional)</span></p></li>
                                <li>
                                <?php 
                if(empty($company_detail['company_website'])){
                    $website = 'http://';    
                }else{
                    $website = 'http://'.$company_detail['company_website'];
                }
                
                echo form_input('website',set_value('website',$website)); ?>
                <?php echo form_error('website','<p id="error_recaptcha" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?>
                </li>
                            </ul>
                        </div>
                        <div class="clear"></div>
                   	</li>
                  </ul>
            </div>
            
            <div class="email_section001">
            	<ul>
                	<li>
                    	<div class="list_div031"><h3 class="style18">location info</h3></div>
                    	<div class="list_div04">
                    	  <p class="txt12">cities : <span>(Optional)</span></p></div>
                        <div class="clear"></div>
                   	</li>
                    <li>
                    	<div class="list_div031">
                        <div class="height10"></div>
                        <p class="redTxt12">Geographical location for fast directory filtering.
                        <br />
                        If you want to add more location <a href="<?php site_url('directory/package') ?>"> Click here</a>
                        </p>
                    	</div>
                    	<div class="list_div04">
                        	<select name="province_id" disabled="disabled">
                                <option value="">Select cities</option>
                                <?php if(!empty($region_list)){
                              foreach($region_list as $key =>$value){
                             if($value['country'] == '2541')
                            $region_list_1[] = $value;
                            
                            if($value['country'] == '2540')
                            $region_list_2[] = $value;
 
                                             }
                            }
                            if(!empty($region_list_1)): ?><optgroup label="Standard Cities" >
                                <?php foreach($region_list_1 as $key=>$value): ?>
                                <option value="<?php echo $value['id']?>" <?php echo ($company_detail['region_id']==$value['id'])?'selected':'';?>><?php echo $value['name'] ?></option>
                                <?php endforeach;?></optgroup>
                                <?php endif;
                             if(!empty($region_list_2)): ?><optgroup label="International Cities" >
                                <?php foreach($region_list_2 as $key=>$value): ?>
                                <option value="<?php echo $value['id']?>" <?php echo ($company_detail['region_id']==$value['id'])?'selected':'';?>><?php echo $value['name'] ?></option>
                                <?php endforeach;?></optgroup>
                                <?php endif;
                            
                            ?> 
                                </select>
                                <?php echo form_error('province_id','<p id="error_recaptcha" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?>
                            <div class="height10"></div>
                            <ul>
                            	<li>
                            	  <p class="txt12">Town: <span>(optional)</span></p></li>
                                <li>
                                <?php echo form_input(array('name'=>'city_name'),set_value('city_name',$company_detail['city_name'])); ?>
                <?php echo form_error('city_name','<p id="error_recaptcha" class="inform f12 error_message"><strong>Error:</strong>','</p>') ?>
                </li>
                           </ul>
                        </div>
                        <div class="clear"></div>
                   	</li>
                  </ul>
            </div>
            <div class="height10"></div>
          
          <div class="height10"></div>
            <div class="email_section001">
            	<div class="div15">
                	<h3 class="style18">Your Profile Picture</h3>
                    <div class="height20"></div>
                    <p class="redTxt12">(OPTIONAL) <br />
                    Upload your  picture to display on your advert.</p>
                   <div class="height10"></div>
                   <div style="height:70px;"></div>
                   <label class="cabinet"> 
            
                    <input type="file" class="file" id="fileToUpload" name="fileToUpload" onchange="return ajaxFileUpload();" />
            
                </label>
         		  <div class="height20"></div>
                    
                </div>
                <div class="div16" id="info" style="min-height:120px; overflow:hidden;">
                	
                    <img id="loading" src="<?php echo base_url()?>image/loading_blue.gif" style="display:none;position:absolute;z-index:1000;left:65px;top:60px" />   
                    
                	<?php if(!empty($company_detail['company_logo'])){?>
                            <img src="<?php echo base_url()?>uploads/directory/company_logo/thumb/<?php echo $company_detail['company_logo']?>" width="150"><!--height="160"-->
                            <input type="hidden" name="upload" value="<?php echo $company_detail['company_logo']?>">
                        <?php } else{?>
                            <img src="<?php echo base_url()?>xhtml/img/advertiser.gif" width="150" height="150">
                    <?php } ?>
                </div>
                <div class="div17">
                	<p class="redTxt12">Upload a Your profile picture in RGB JPG format only.<br /><br />

To replace exsiting picture, simply select and upload another image.<br /><br />

Click <strong><a href="" id="clear">clear picture</a></strong> to remove the Picture uploaded here.</p>
                </div>
                <div class="clear"></div>
            </div>
           <div class="line"></div>
           <?php 
                $form_button = array(
                  'type'=>'submit',
                  'name'=>'submit',
                  'value'=>'submit',
                  'content'=>'Submit',
				  
                );
                echo form_button($form_button) ?>
                 <?php echo form_close(); ?>
        
                </div> 
    	</div>

<?php $this->load->view(TEMPLATE_NAME.'/front/side_right'); ?>
     <div class="clear"></div> 
	</div>
</div>
<!--body content ends-->


<?php
$CI->load->library("front/footer_lib");
$CI->footer_lib->display_footer();
$CI->footer_lib->display_footer_element();

?>